package com.spring.housing.jobBase.handel;

import com.google.gson.reflect.TypeToken;
import com.spring.housing.jobBase.config.JobConfig;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import com.xxl.job.core.handler.IJobHandler;

import com.xxl.job.core.handler.annotation.XxlJob;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import sun.plugin.util.UIUtil;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Slf4j

@Component
public class TokenInit {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Value("${xxl.job.executor.port}")
    private int port;
    @Autowired
    RedisTemplate redisTemplate;
    private static Logger logger = LoggerFactory.getLogger(TokenInit.class);
    @XxlJob("bussStatisticsHandler")
    public ReturnT<String> execute(String param)
    {
        XxlJobHelper.log("开始执行{}","success!");
        XxlJobHelper.log("开始执行{}","更新token...");
        logger.info("进入成功{}",port);
        logger.debug("ceshi");
        log.info( XxlJobHelper.getJobParam());
        String s = UUID.randomUUID().toString();
        jdbcTemplate.update("update access_token set accessToken =? , date=? where id =1",s,new Date());
        redisTemplate.opsForValue().set("accessToken",s);
        log.info("端口号:"+port);
        log.info("accessToken为:"+s );
        return  ReturnT.SUCCESS;
    }


}
